package com.lijian.netty.nio6;

import java.nio.IntBuffer;
import java.security.SecureRandom;

/**
 * @author lj02
 * @desc
 * @date 2018/11/28
 */
public class NioTest4 {
    public static void main(String[] args) {
        IntBuffer intBuffer = IntBuffer.allocate(10);

        for (int i = 0; i < 5; i++) {
            intBuffer.put(new SecureRandom().nextInt(20));
        }
        System.out.println("before limit is " + intBuffer.limit());
        intBuffer.flip();//翻转 , 将缓存字节数组的指针设置为数组的开始序列即数组下标0。这样就可以从buffer开头，对该buffer进行遍历（读取）了

        System.out.println("after limit is " + intBuffer.limit());

        while (intBuffer.hasRemaining()) {

            System.out.println("limit is " + intBuffer.limit());
            System.out.println("position is " + intBuffer.position());
            System.out.println("capacity is " + intBuffer.capacity());

            System.out.println(intBuffer.get());
        }
    }
}
